/// res_load_pack()
/// @desc Unzips an archive and stores the textures in the resource.

var fname = load_folder + "\\" + filename;

switch (load_stage)
{
	// Unzip archive
	case "unzip":
	{
		debug("res_load_pack", "unzip")
		
		if (type != e_res_type.PACK_UNZIPPED)
		{
			if (unzip(fname) < 0)
			{
				log("Error unzipping pack")
				error("errorunzippack")
				with (app)
					load_next()
				return 0
			}
		}
		
		type = e_res_type.PACK
		load_stage = "modeltextures"
		load_assets_dir = unzip_directory
		res_load_pack_version()
		
		with (app)
		{
			popup_loading.text = text_get("loadpackmodeltextures")
			popup_loading.progress = 1 / 4
		}
		break
	}
	
	// Load model textures
	case "modeltextures":
	{
		debug("res_load_pack", "modeltextures")
		res_load_pack_model_textures()
		
		load_stage = "blocktextures"
		with (app)
		{
			popup_loading.text = text_get("loadpackblocktextures")
			popup_loading.progress = 2 / 4
		}
		break
	}
	
	// Load block textures
	case "blocktextures":
	{
		debug("res_load_pack", "blocktextures")
		
		// Legacy pack support
		file_rename_lib(load_assets_dir + mc_textures_directory + "blocks", load_assets_dir + mc_textures_directory + "block")
		
		res_load_pack_block_textures()
		
		load_stage = "itemtextures"
		with (app)
		{
			popup_loading.text = text_get("loadpackitemtextures")
			popup_loading.progress = 3 / 4
		}
		break
	}
	
	// Load item textures and finish
	case "itemtextures":
	{
		debug("res_load_pack", "itemtextures")
		
		// Legacy pack support
		file_rename_lib(load_assets_dir + mc_textures_directory + "items", load_assets_dir + mc_textures_directory + "item")
		
		res_load_pack_item_textures()
		res_load_pack_particle_textures()
		res_load_pack_misc()
		res_update_colors()
		
		ready = true
		
		log("Pack loaded")
		
		// Update project and load next in the queue
		with (obj_template)
			if (item_tex = other.id)
				render_generate_item()
					
		with (obj_particle_type)
			if (sprite_tex = other.id || sprite_template_tex = other.id)
				ptype_update_sprite_vbuffers()
				
		with (app.bench_settings)
			if (item_tex = other.id)
				render_generate_item()
				
		with (app)
		{
			if (background_ground_tex = other.id)
				background_ground_update_texture()
			
			if (background_sky_clouds_tex = other.id)
				background_sky_update_clouds()
			
			load_next()
		}
				
		break
	}
}

